


* log using "C:\Users\Kevin\Dropbox\iREDS\Data\data_and_codebook\iREDS_wide.smcl", replace



use "C:\Users\Kevin\Dropbox\iREDS\Data\data_and_codebook\ireds_dataset_wide.dta", clear

* 6 is NA for these items
recode t0_labdyn_discussunderstand t0_genrcr_discussdominate t1_labdyn_discussunderstand t1_genrcr_discussdominate (6=.)



* Assignment
tab condition 
* gen posttest=1-pretest

* Covariate factors (recode t0_gender 3->0 for 0= not male)
capture drop urm
gen urm=t0_ethnicity
replace urm=t1_ethnicity if t0_ethnicity==.
recode urm (1=0) (2=1) (3=1) (4=0) (5=0) (6=0)
capture drop urmxcond
gen urmxcond = urm*condition
capture drop male
gen male = t0_gender
replace male=t1_gender if t0_gender==.
recode male (2=0) (3=0)
capture drop malexcond
gen malexcond=male*condition
capture drop pi_role
gen pi_role=t0_labposition
replace pi_role = t1_labposition if t0_labposition==.
recode pi_role (2/7=0)
capture drop pi_rolexcond
gen pi_rolexcond=pi_role*condition
replace t0_department = t1_department if t0_department==.
* egen department = group(t0_department)
* tab1 urm male pi_role department labid
capture drop lifesci
gen lifesci = t0_department==1 | t0_department==2  | t0_department==3  | t0_department==4  | t0_department==8  | t0_department==10  | t0_department==11  | t0_department==12  | t0_department==14
capture drop engineering
gen engineering = t0_department==15
capture drop lifescixcond
gen lifescixcond = lifesci*condition
capture drop engxcond
gen engxcond = engineering*condition




bysort labid: gen labmnum=_n
bysort labid: egen apmean0=mean(t0_authorpolicy_yesno)
bysort labid: egen apmean1=mean(t1_authorpolicy_yesno)
bysort labid: egen dmmean0=mean(t0_datamanagement_yesno)
bysort labid: egen dmmean1=mean(t1_datamanagement_yesno)
* fascinating that lab policies are an individual perception!
tab1 apmean0 apmean1 if labmnum==1
tab1 dmmean0 dmmean1 if labmnum==1


* recode these variables becuase often there is only one person in the end category, so not statistically distinct
tab1 t0_genrcr_relevant t0_genrcr_discussdeptresp t0_genrcr_convoresponsibity  t0_genrcr_discussotherlabs
tab1 t1_genrcr_relevant t1_genrcr_discussdeptresp t1_genrcr_convoresponsibity  t1_genrcr_discussotherlabs
tab1 t0_ap_understandrationale t0_ap_understandimportance t0_ap_understandimplications
tab1 t1_ap_understandrationale t1_ap_understandimportance t1_ap_understandimplications
tab1 t0_dm_understandrationale t0_dm_understandimportance t0_dm_understandimplications
tab1 t1_dm_understandrationale t1_dm_understandimportance t1_dm_understandimplications
tab1 t0_prevrcrelem_authorship t0_prevrcrelem_datacollection t0_prevrcrelem_dataarchiving t0_prevrcrelem_datasharing
tab1 t1_prevrcrelem_authorship t1_prevrcrelem_datacollection t1_prevrcrelem_dataarchiving t1_prevrcrelem_datasharing
tab1 t0_labdyn_disagreements t0_ap_disagreements t0_dm_disagreements t0_genrcr_discusschangedviews
tab1 t1_labdyn_disagreements t1_ap_disagreements t1_dm_disagreements t1_genrcr_discusschangedviews
tab1 t0_labdyn_disagreevalid t0_genrcr_discussdominate t0_labdyn_discussrespect t0_labdyn_discussunderstand t0_genrcr_coworkerspractice
tab1 t1_labdyn_disagreevalid t1_genrcr_discussdominate t1_labdyn_discussrespect t1_labdyn_discussunderstand t1_genrcr_coworkerspractice
tab1 t0_lpstore_lab_repo t0_genrcr_opendata_yesno t0_genrcr_openmat_yesno t0_genrcr_contribusystem_yesno 
tab1 t1_lpstore_lab_repo t1_genrcr_opendata_yesno t1_genrcr_openmat_yesno t1_genrcr_contribusystem_yesno 
tab1 t0_genrcr_imparchive_dataset t0_genrcr_imparchive_manuscri t0_genrcr_imparchive_material t0_genrcr_ecopies
tab1 t1_genrcr_imparchive_dataset t1_genrcr_imparchive_manuscri t1_genrcr_imparchive_material t1_genrcr_ecopies

recode t0_genrcr_relevant t0_genrcr_discussdeptresp t0_genrcr_convoresponsibity (5=4) (4=3) (3=2) (2=1)
recode t1_genrcr_relevant t1_genrcr_discussdeptresp t1_genrcr_convoresponsibity (5=4) (4=3) (3=2) (2=1)
recode  t0_genrcr_discussotherlabs (5=4)
recode  t1_genrcr_discussotherlabs (5=4)
recode t0_ap_understandrationale t0_ap_understandimportance t0_ap_understandimplications (5=4) (4=3) (3=2) (2=1)
recode t1_ap_understandrationale t1_ap_understandimportance t1_ap_understandimplications (5=4) (4=3) (3=2) (2=1)
recode t0_dm_understandrationale t0_dm_understandimportance t0_dm_understandimplications (5=4) (4=3) (3=2) (2=1)
recode t1_dm_understandrationale t1_dm_understandimportance t1_dm_understandimplications (5=4) (4=3) (3=2) (2=1)
recode t0_labdyn_disagreements t0_ap_disagreements t0_dm_disagreements t0_genrcr_discusschangedviews (5=4) 
recode t1_labdyn_disagreements t1_ap_disagreements t1_dm_disagreements t1_genrcr_discusschangedviews (5=4) 
recode t0_labdyn_disagreevalid t0_genrcr_discussdominate t0_labdyn_discussrespect t0_labdyn_discussunderstand t0_genrcr_coworkerspractice (5=4) (4=3) (3=2) (2=1) 
recode t1_labdyn_disagreevalid t1_genrcr_discussdominate t1_labdyn_discussrespect t1_labdyn_discussunderstand t1_genrcr_coworkerspractice (5=4) (4=3) (3=2) (2=1) 
recode t0_genrcr_imparchive_dataset t0_genrcr_imparchive_manuscri t0_genrcr_imparchive_material t0_genrcr_ecopies (5=4) (4=3) (3=2) (2=1)
recode t1_genrcr_imparchive_dataset t1_genrcr_imparchive_manuscri t1_genrcr_imparchive_material t1_genrcr_ecopies (5=4) (4=3) (3=2) (2=1)

* find (complete case) pretreatment means which we use to aid convergence
summ t0_genrcr_relevant t0_genrcr_discussdeptresp t0_genrcr_convoresponsibity t0_genrcr_discussotherlabs 
summ t0_ap_understandrationale t0_ap_understandimportance t0_ap_understandimplications 
summ t0_dm_understandrationale t0_dm_understandimportance t0_dm_understandimplications 
summ t0_prevrcrelem_authorship t0_prevrcrelem_datacollection t0_prevrcrelem_dataarchiving t0_prevrcrelem_datasharing 
summ t0_labdyn_disagreements t0_ap_disagreements t0_dm_disagreements 
summ t0_labdyn_disagreevalid t0_genrcr_discussdominate t0_labdyn_discussrespect t0_labdyn_discussunderstand t0_genrcr_coworkerspractice 
summ t0_lpstore_lab_repo t0_genrcr_opendata_yesno t0_genrcr_openmat_yesno t0_genrcr_contribusystem_yesno 
summ t0_genrcr_imparchive_dataset t0_genrcr_imparchive_manuscri t0_genrcr_imparchive_material t0_genrcr_ecopies


* Now let's create PCA (descriptive) versions of the scales
* 1. Discussion practice views (Likert 4)
alpha t0_genrcr_relevant t0_genrcr_discussdeptresp t0_genrcr_convoresponsibity  t0_genrcr_discussotherlabs
polychoric t0_genrcr_relevant t0_genrcr_discussdeptresp t0_genrcr_convoresponsibity  t0_genrcr_discussotherlabs
polyfactor
predict t0_discpractice

* 2. AP policy (Likert 4)
alpha t0_ap_understandrationale t0_ap_understandimportance t0_ap_understandimplications
polychoric t0_ap_understandrationale t0_ap_understandimportance t0_ap_understandimplications
polyfactor
predict t0_apunconditional

* 3. DM policy (Likert 4)
alpha t0_dm_understandrationale t0_dm_understandimportance t0_dm_understandimplications
polychoric t0_dm_understandrationale t0_dm_understandimportance t0_dm_understandimplications
polyfactor
predict t0_dmunconditional

* 4. Belifes regarding the elements of RCR (Dichotomous) -- this one we do not use in the analysis -- the model does not converge with this scale as DV!
alpha t0_prevrcrelem_authorship t0_prevrcrelem_datacollection t0_prevrcrelem_dataarchiving t0_prevrcrelem_datasharing
polychoric t0_prevrcrelem_authorship t0_prevrcrelem_datacollection t0_prevrcrelem_dataarchiving t0_prevrcrelem_datasharing
polyfactor
predict t0_ethicsbeliefs

* 5. disagreements (Likert 4)
alpha t0_labdyn_disagreements t0_ap_disagreements t0_dm_disagreements
polychoric t0_labdyn_disagreements t0_ap_disagreements t0_dm_disagreements
polyfactor
predict t0_disagreements

* 6. respectful discussion (Likert 4)
alpha t0_labdyn_disagreevalid t0_genrcr_discussdominate t0_labdyn_discussrespect t0_labdyn_discussunderstand t0_genrcr_coworkerspractice
polychoric t0_labdyn_disagreevalid t0_genrcr_discussdominate t0_labdyn_discussrespect t0_labdyn_discussunderstand t0_genrcr_coworkerspractice
polyfactor
predict t0_discussresp

* 7. Open science I (Dichotomous) -- this one we do not use in the analysis -- the model does not converge with this scale as DV!
alpha t0_lpstore_lab_repo t0_genrcr_opendata_yesno t0_genrcr_openmat_yesno t0_genrcr_contribusystem_yesno
polychoric t0_lpstore_lab_repo t0_genrcr_opendata_yesno t0_genrcr_openmat_yesno t0_genrcr_contribusystem_yesno 
polyfactor
predict t0_openscience1

* 8. Open science II (Likert 4)
alpha t0_genrcr_imparchive_dataset t0_genrcr_imparchive_manuscri t0_genrcr_imparchive_material t0_genrcr_ecopies
polychoric t0_genrcr_imparchive_dataset t0_genrcr_imparchive_manuscri t0_genrcr_imparchive_material t0_genrcr_ecopies
polyfactor
predict t0_openscience2



* 1. Discussion practice views (Likert 4)
polychoric t1_genrcr_relevant t1_genrcr_discussdeptresp t1_genrcr_convoresponsibity  t1_genrcr_discussotherlabs
polyfactor
predict t1_discpractice

* 2. AP policy (Likert 4)
polychoric t1_ap_understandrationale t1_ap_understandimportance t1_ap_understandimplications
polyfactor
predict t1_apunconditional

* 3. DM policy (Likert 4)
polychoric t1_dm_understandrationale t1_dm_understandimportance t1_dm_understandimplications
polyfactor
predict t1_dmunconditional

* 4. Belifes regarding the elements of RCR (Dichotomous) -- this one we do not use in the analysis -- the model does not converge with this scale as DV!
polychoric t1_prevrcrelem_authorship t1_prevrcrelem_datacollection t1_prevrcrelem_dataarchiving t1_prevrcrelem_datasharing
polyfactor
predict t1_ethicsbeliefs

* 5. disagreements (Likert 4)
polychoric t1_labdyn_disagreements t1_ap_disagreements t1_dm_disagreements
polyfactor
predict t1_disagreements

* 6. respectful discussion (Likert 4)
polychoric t1_labdyn_disagreevalid t1_genrcr_discussdominate t1_labdyn_discussrespect t1_labdyn_discussunderstand t1_genrcr_coworkerspractice
polyfactor
predict t1_discussresp

* 7. Open science I (Dichotomous) -- this one we do not use in the analysis -- the model does not converge with this scale as DV!
polychoric t1_lpstore_lab_repo t1_genrcr_opendata_yesno t1_genrcr_openmat_yesno t1_genrcr_contribusystem_yesno 
polyfactor
predict t1_openscience1

* 8. Open science II (Dichotomous)
polychoric t1_genrcr_imparchive_dataset t1_genrcr_imparchive_manuscri t1_genrcr_imparchive_material t1_genrcr_ecopies
polyfactor
predict t1_openscience2



 saveold "C:\Users\Kevin\Dropbox\iREDS\Data\data_and_codebook\ireds_dataset_wide_v12.dta", version(12) replace

 use "C:\Users\Kevin\Dropbox\iREDS\Data\data_and_codebook\ireds_dataset_wide_v12.dta", clear

 * descriptive analyses
 
summ t0_discpractice t0_apunconditional t0_dmunconditional t0_ethicsbeliefs t0_disagreements t0_discussresp t0_openscience2 
summ t1_discpractice t1_apunconditional t1_dmunconditional t1_ethicsbeliefs t1_disagreements t1_discussresp t1_openscience2 

reg t1_discpractice t0_discpractice condition i.labid
reg t1_discussresp t0_discussresp condition i.labid
reg t1_disagreements t0_disagreements condition i.labid
reg t1_apunconditional t0_apunconditional condition i.labid
reg t1_dmunconditional t0_dmunconditional condition i.labid
reg t1_openscience2 t0_openscience2 condition i.labid
* reg t1_outcomes t0_outcomes condition i.labid /* this is just due to change in authorship policy */

reg t1_discpractice t0_discpractice condition pi_role pi_rolexcond male malexcond urm urmxcond 
reg t1_discussresp t0_discussresp condition pi_role pi_rolexcond male malexcond urm urmxcond 
reg t1_disagreements t0_disagreements condition pi_role pi_rolexcond male malexcond urm urmxcond 
reg t1_apunconditional t0_apunconditional condition pi_role pi_rolexcond male malexcond urm urmxcond 
reg t1_dmunconditional t0_dmunconditional condition pi_role pi_rolexcond male malexcond urm urmxcond 
reg t1_openscience2 t0_openscience2 condition pi_role pi_rolexcond male malexcond urm urmxcond 


* assignment uncorrelated with the pretest outcomes
reg t0_discpractice condition i.labid
reg t0_discussresp condition i.labid
reg t0_disagreements condition i.labid
reg t0_apunconditional condition i.labid
reg t0_dmunconditional condition i.labid
reg t0_openscience condition i.labid



* MLE results
xtset labid
ologit t1_genrcr_discusschangedviews t0_genrcr_discusschangedviews condition
* xtologit t1_genrcr_discusschangedviews t0_genrcr_discusschangedviews condition, i(labid)
xtlogit t1_authorpolicy_yesno t0_authorpolicy_yesno condition, re
logit t1_authorpolicy_yesno t0_authorpolicy_yesno condition, cluster(labid)
xtlogit t1_datamanagement_yesno t0_datamanagement_yesno condition, re
logit t1_datamanagement_yesno t0_datamanagement_yesno condition, cluster(labid)

* set the coef on pretreatment to 1...
gen diffauthorpolicy= t1_authorpolicy_yesno - t0_authorpolicy_yesno
ologit diffauthorpolicy condition, cluster(labid)
gen diffdmpolicy = t1_datamanagement_yesno- t0_datamanagement_yesno
ologit diffdmpolicy condition, cluster(labid)
gen diffchangeviews = t1_genrcr_discusschangedviews- t0_genrcr_discusschangedviews
ologit diffchangeviews condition, cluster(labid)
* the results are the same only a bigger effect estimate for diffchangeviews


